﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Lister;
using COFE.Core;
using COFE.Core.Entry;

namespace COFE.Core
{
    public class RedirectPropertyProvider : PropertyProviderBase<Tuple<IDirectoryInfo, IPropertyProvider>>
    {

        #region Constructor

        internal RedirectPropertyProvider(IDirectoryInfo parent, IPropertyProvider propProvider)
            : base(new Tuple<IDirectoryInfo, IPropertyProvider>(parent, propProvider))
        {
            RegisterMethod(FileSystemInfoProperties.Parent, (e, p) => { return parent; });
            RegisterMethod(FileSystemInfoProperties.ParentParseName, (e, p) => { return parent.ParseName; });
            foreach (var prop in propProvider.GetSupportedProperty())
                switch ((int)prop)
                {
                    case (int)FileSystemInfoProperties.Parent :
                    case (int)FileSystemInfoProperties.ParentParseName:
                        break;
                    case (int)FileSystemInfoProperties.COFEAttributes :
                        RegisterMethod(prop, (e, p) => 
                        { return COFEAttributes.AlreadyCached | (COFEAttributes)e.Item2.GetProperty(p).Value; });
                        break;
                    default :
                        if (propProvider.IsPropertyReadOnly(prop))
                            RegisterMethod(prop, (e, p) => { return e.Item2.GetProperty(p).Value; });
                        else RegisterMethod(prop, (e, p) => { return e.Item2.GetProperty(p).Value; }, 
                            (e, p, v) => { e.Item2.SetProperty(p, v); });
                        break;
                }

        }

        internal RedirectPropertyProvider(IDirectoryInfo parent, IFileSystemInfo redirectEntry)
            : this(parent, (redirectEntry as IInternalFileSystemInfoExA).PrimaryPropertyProvider)
        {
  
        }
        #endregion

        #region Methods

        public static IInternalFileSystemInfoExA CreateRedirectEntry(IDirectoryInfo parent, IFileSystemInfo redirectEntry)
        {
            return COFEShared.EntryConstructor.CreateEntry(new RedirectPropertyProvider(parent, redirectEntry), Profile.EntryConstructionFlags.DefaultWithoutCache);
        }

        #endregion

        #region Data

        #endregion

        #region Public Properties

        #endregion

    }
}
